package com.ruoyi.agencyfund.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.agencyfund.domain.AgencyFund;
import com.ruoyi.agencyfund.service.IAgencyFundService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 运单代收款业务Controller
 *
 * @author dxw
 * @date 2022-05-04
 */
@RestController
@RequestMapping("/fund")
public class AgencyFundController extends BaseController
{
    @Autowired
    private IAgencyFundService agencyFundService;

    /**
     * 查询运单代收款业务列表
     */
    @RequiresPermissions("agencyfund:fund:list")
    @GetMapping("/list")
    public TableDataInfo list(AgencyFund agencyFund)
    {
        startPage();
        List<AgencyFund> list = agencyFundService.selectAgencyFundList(agencyFund);
        return getDataTable(list);
    }

    /**
     * 导出运单代收款业务列表
     */
    @RequiresPermissions("agencyfund:fund:export")
    @Log(title = "运单代收款业务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgencyFund agencyFund)
    {
        List<AgencyFund> list = agencyFundService.selectAgencyFundList(agencyFund);
        ExcelUtil<AgencyFund> util = new ExcelUtil<AgencyFund>(AgencyFund.class);
        util.exportExcel(response, list, "运单代收款业务数据");
    }

    /**
     * 获取运单代收款业务详细信息
     */
    @RequiresPermissions("agencyfund:fund:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(agencyFundService.selectAgencyFundById(id));
    }

    /**
     * 新增运单代收款业务
     */
    @RequiresPermissions("agencyfund:fund:add")
    @Log(title = "运单代收款业务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgencyFund agencyFund)
    {
        return toAjax(agencyFundService.insertAgencyFund(agencyFund));
    }

    /**
     * 修改运单代收款业务
     */
    @RequiresPermissions("agencyfund:fund:edit")
    @Log(title = "运单代收款业务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgencyFund agencyFund)
    {
        return toAjax(agencyFundService.updateAgencyFund(agencyFund));
    }

    /**
     * 删除运单代收款业务
     */
    @RequiresPermissions("agencyfund:fund:remove")
    @Log(title = "运单代收款业务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(agencyFundService.deleteAgencyFundByIds(ids));
    }

    /**
     * 查询运单代收款业务列表
     */
    @RequiresPermissions("agencyfund:fund:list")
    @GetMapping("/history")
    public TableDataInfo history(AgencyFund agencyFund)
    {
        startPage();
        List<AgencyFund> list = agencyFundService.selectHistory(agencyFund);
        return getDataTable(list);
    }
}
